package com.woniuxy.microsysserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.woniuxy.common.bean.ResultMsg;
import com.woniuxy.microsysserver.feign.MicroMallServerFeign;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/feign")
public class FeignController {

    /**
     * 将OpenFeign接口实例装配到此处
     */
    @Resource
    private MicroMallServerFeign microMallServerFeign;

    @GetMapping(value = "/get",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultMsg getAll(){

        String allCommodity = microMallServerFeign.findAllCommodity();

        //如何将字符串转换为Java对象
        ResultMsg rm = JSONObject.parseObject(allCommodity).toJavaObject(ResultMsg.class);

        return rm;
    }

    @RequestMapping("/getMoney")
    public ResultMsg getMoney(){
        String mouthSales = microMallServerFeign.getCurrentMouthSales();

        ResultMsg rm = JSONObject.parseObject(mouthSales).toJavaObject(ResultMsg.class);
        return rm;
    }

}
